<?php
/**
 * @var $this BackOfficeController
 * @var $form CActiveForm
 *
 */
?>
<div class="form wide">

    <?php $form = $this->beginWidget('CActiveForm', array(
    'id' => 'product-form',
    'enableClientValidation' => true,
    'clientOptions' => array(
        'validateOnSubmit' => true,
        'afterValidate'=>"js:function(form,data,hasError){
            $('ul.ui-tabs-nav li a').removeClass('error');
            if (hasError)
            {
                $('#product-form div.row.error').each(function(index, value){
                    var tab_id = $(this).parents('div.ui-tabs-panel').attr('id');
                    $('ul.ui-tabs-nav li a[title=#'+tab_id+']').addClass('error');    
                });
                return false;    
            }
            else return true;
        }"
    ),
    //'enableAjaxValidation'=>false,
)); ?>
    <p class="note">Fields with <span class="required">*</span> are required.</p>
    <?php //echo $form->errorSummary($model); ?>

    <?php
    $langTab = array();
    $langList = Language::model()->findAll('status=1');
    if (count($langList)) {
        foreach ($langList as $i => $lang) {
            $this->beginClip($lang->name);
            if ($model->isNewRecord) {
                $languageProduct = new LanguageProduct();
                $languageProduct->locale = $lang->locale;
            }
            else {
                $languageProduct = LanguageProduct::model()->findByAttributes(array(
                    'product_id' => $model->id,
                    'locale' => $lang->locale,
                ));
                if (!$languageProduct) {
                    $languageProduct = new LanguageProduct();
                    $languageProduct->locale = $lang->locale;
                }
            }
            $this->renderPartial('Product.views.admin.languageProduct._form', array(
                'model' => $languageProduct,
                'form' => $form,
                'i' => $i,
            ));
            $this->endClip();
            $langTab[$lang->name] = $this->Clips[$lang->name];
        }

        if (count($langTab)) {
            $this->widget('zii.widgets.jui.CJuiTabs', array(
                'id' => 'language-tabs',
                'tabs' => $langTab,
            ));
        }
    }
    ?>

    <?php $this->beginClip('general');?>
    <?php if (!$model->IsNewRecord) echo $form->hiddenField($model, "id"); ?>
    <div class="row">
        <?php echo $form->labelEx($model, 'category_id'); ?>
        <?php
        $this->widget('CategoryDropDownList', array(
            'model' => $model,
            'attribute' => 'category_id',
            'rootId' => ProductSettings::ROOT_CATEGORY_ID,
            'includeRoot' => false,
            'htmlOptions' => array(
                'prompt' => '-- Choose The Category --',
            ),
        ));
        ?>
        <?php echo $form->error($model, 'category_id'); ?>
    </div>


    <div class="row">
        <?php echo $form->labelEx($model, 'images'); ?>
        <div style="padding-left: 210px;">
            <?php $this->widget('Admin.components.ImageWidget', array(
            'model' => $model,
            'imageAttribute' => 'images',
            'path' => Settings::PRODUCT_PATH,
            'form' => $form));?>
        </div>
        <?php echo $form->error($model, 'images'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'status'); ?>
        <?php echo $form->dropDownList($model, 'status', $model->getStatusOptions()); ?>
        <?php echo $form->error($model, 'status'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'price'); ?>
        <?php
        echo $form->textField($model, 'price', array('size' => 20, 'maxlength' => 20, 'style'=>'width: 168px;'));
        echo $form->dropDownList($model, 'currency', $model->getCurrencyList(), array('style'=>'margin-left: 5px;'));
        ?>
        <?php echo $form->error($model, 'price'); ?>
    </div>

    <?php if (!$model->isNewRecord) : ?>
    <div class="row">
        <?php echo $form->labelEx($model, 'create_time'); ?>
        <?php echo Yii::app()->getDateFormatter()->formatDateTime($model->create_time); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model, 'update_time'); ?>
        <?php echo Yii::app()->getDateFormatter()->formatDateTime($model->update_time); ?>
    </div>
    <?php endif;?>
    <?php $this->endClip();?>

    <?php
    $tabs = array(
        'General' => $this->Clips['general'],
    );
    $this->widget('zii.widgets.jui.CJuiTabs', array(
        'id' => 'product-tabs',
        'tabs' => $tabs,
    ));
    ?>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

    <?php $this->endWidget(); ?>

</div><!-- form -->
